package com.sourceQ.common.core.validation;

import cn.hutool.core.util.StrUtil;
import com.sourceQ.common.core.utils.validation.ValidationUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author: SourceQ
 * @create: 2024-04-23 17:35
 * @Description:
 */
public class MobileValidator implements ConstraintValidator<Mobile, String> {
    @Override
    public void initialize(Mobile constraintAnnotation) {
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        // 如果手机号为空，默认不校验，即校验不通过
        if (StrUtil.isEmpty(s)) {
            return false;
        }
        return ValidationUtils.isMobile(s);
    }
}
